//---------------------------------------------------------------------
//  This file is part of the Background Motion solution.
// 
//  Copyright (C) Mindscape (TM).  All rights reserved.
//  http://www.mindscape.co.nz
// 
//  THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//---------------------------------------------------------------------

using System.Collections.Generic;

using Mindscape.BackgroundMotion.Core.Model;

namespace Mindscape.BackgroundMotion.Core.Search
{
  /// <summary>
  /// Static gateway to allow access to our current search engine provider
  /// </summary>
  /// <remarks>There is a tight binding to the Lucene implementation, this should be refactored out to use the ServiceLocator</remarks>
  /// <typeparam name="T">The generic type of the resource we want to search over</typeparam>
  public static class SearchEngine<T>
    where T : class, IIndexable
  {
    private static readonly ISearchEngine _current = new LuceneSearchEngine();

    /// <summary>
    /// Searches the specified query.
    /// </summary>
    /// <param name="query">The query.</param>
    /// <param name="pageSize">Size of the page.</param>
    /// <param name="page">The page.</param>
    /// <param name="totalResults">The total results.</param>
    /// <returns></returns>
    public static IList<T> Search(string query, int pageSize, int page, out int totalResults)
    {
      return _current.Search<T>(query, pageSize, page, out totalResults);
    }

    /// <summary>
    /// Indexes the specified item.
    /// </summary>
    /// <param name="item">The item.</param>
    public static void Index(IIndexable item)
    {
      _current.Index(item);
    }

    /// <summary>
    /// Removes the specified item.
    /// </summary>
    /// <param name="item">The item.</param>
    public static void Remove(IIdentifiable item)
    {
      _current.Remove(item);
    }

    /// <summary>
    /// Rebuilds the index.
    /// </summary>
    public static void RebuildIndex()
    {
      _current.RebuildIndex<T>();
    }
  }
}